﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Telerik.WebControls;
using System.Collections.Generic;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Common.Upload;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_DL_Project_StuCertificate : PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        Button1.Visible = true;
        FileUpload1.Visible = false;
        btn_UploadFile.Visible = false;
        lbl_Certificate.Text = "<img title=\"Certificate\" src=\"../../../images/Certificate/indexImg/certificate.jpg?ID=" + DateTime.Now + "\" />";
        Button1.Text = "替换";
        lbl_StudentLoginNum_InfoTitle.Text = "证书管理";
        btn_UploadFile.Text = "确定";
    }

    //检查上传文件类型
    public bool IsUploadFileType(string extension)
    {
        string allowExtensions = "gif|jpg";    //允许上传的类型
        if (!opCourse.IsAllowedExtension(extension, allowExtensions))
        {
            lbl_FileUpload_msg_FileType.Text = "只允许上传文件类型为：" + allowExtensions;
            return false;
        }
        return true;
    }

    protected void btn_Click(object sender, EventArgs e)
    {

        Button1.Visible = false;
        FileUpload1.Visible = true;
        btn_UploadFile.Visible = true;
    }

    protected void btnUploadFile_Click(object sender, EventArgs e)
    {
        string Url = string.Empty;
        btn_UploadFile.Enabled = false;
        foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
        {
            Url = WebUtils.WebRoot + "/images/Certificate/indexImg/";
            string Path = Server.MapPath(Url);

            //如果路径不存在，则创建
            if (System.IO.Directory.Exists(Path) == false)
            {
                System.IO.Directory.CreateDirectory(Path);
            }

            string filetype = file.GetExtension();
            if (!IsUploadFileType(filetype)) return;

            //组合路径，file.GetName()取得文件名
            string fileName = "certificate.jpg";

            Path = Path + fileName;
            Url = Url + fileName;
            //保存
            file.SaveAs(Path, true);
            lbl_Certificate.Text = "<img title=\"Certificate\" src=\"../../../images/Certificate/indexImg/certificate.jpg\" />";
            Script.ReloadMe();
        }
    }
}
